import O1HD from "../gameEngine";

const {ccclass, property, menu} = cc._decorator;

@ccclass
@menu("框架组件/新手保护")
export default class comFirstPlayerProtect extends cc.Component {
    //
    @property({type: [cc.Node], tooltip: '需要动态隐藏显示的节点拖拽至此，动态加入的节点可通过事件<addFirstPlayerNode>来添加'})
    nodes: cc.Node[] = []

    onLoad() {
        O1HD.on('addFirstPlayerNode', this.addFirstPlayerNode.bind(this));
        //
        this.schedule(this.updateShowNodes.bind(this), 1);
        this.updateShowNodes();
    }

    addFirstPlayerNode(node: cc.Node) {
        this.nodes.push(node);
    }

    updateShowNodes() {
        let show = !O1HD.getServices().userSrv.isFirstPlayerTimeIn();
        for (let node of this.nodes) {
            if (node && node.isValid) {
                node.active = show;
            }
        }
    }
}